<template>

  <div style="height: 100%;">
    <el-container>
      <el-aside width="200px" style="background-color: white;">
        <el-tree :load="loadNode" :props="defaultProps" lazy @node-click="handleNodeClick" :highlight-current="true"
          ></el-tree>
      </el-aside>
      <el-main>
        <manage :parent-node="currentNodeData" @sub="onManageSub"></manage>
      </el-main>
    </el-container>
  </div>
  
</template>

<script>

import manage from './manage.vue'

import { getTreeNodesByParentId } from "@/api/asset/assetCategory.js";

export default {
  name: "AssetCategory",
  components: {
    manage
  },
  data() {
    return {
      currentNode: null,
      currentNodeData: null,
      defaultProps: {
        children: "children",
        label: "name"
      }
    };
  },
  created() {
    
  },
  methods: {
    /** 查询资产分类表列表 */
    loadNode(node, resolve) {
      const data = node.data;
      let parentId = 0;
      if (data) {
        parentId = data.id;
      }

      getTreeNodesByParentId(parentId).then(response => {
        resolve(response);
      });
    },
    handleNodeClick(data, node) {
      this.currentNode = node;
      this.currentNodeData = data;
    },
    onManageSub() {
      if (this.currentNode) {
        this.currentNode.loaded = false;
        this.currentNode.expand();
      }
      
    }
  }
};
</script>
